var loading = false; //状态标记
var hasNextPage = false;
var pageNo = 1;
loadlist();

//下拉刷新
$("#shopWrap").pullToRefresh().on("pull-to-refresh", function () {
    $("#shoplist-content").html("");
    loadlist();
    if (loading) loading = false;
    $("#shopWrap").pullToRefreshDone(); // 重置下拉刷新
});

function loadlist() {
    $.post('/antique/api/userShopCollection/query_list', {
        /* global getCookie */
        token: getCookie('token'),
        start: 0,
        limit: 20,
        showProduct:1
    }, function (result) {
        /* global template */
        var html = template('shoplist', result.data);
        document.getElementById('shoplist-content').innerHTML = html;
        hasNextPage = result.data.hasNextPage;
        if (!result.data.hasNextPage) {
            $('#loadmore').hide();
            $('#nomore').show();
        } else {
            $('#loadmore').show();
            $('#nomore').hide();
        }

        //添加删除事件
        $('.shoplist-item .shoplist-item-top .del').click(function(){
            var shopId = $(this).attr('shopId');
            $.post('/antique/api/userShopCollection/set_collection', {
                shopId:shopId,
                token: getCookie('token'),
                operType:2
            }, function (result) {
                $.toast("取消关注成功!",function(){
                    window.location.reload();
                },1000);
            });
            return false;
        });
    });
}

$('.op .clear').click(function(){
    $.confirm("您确定清空所有关注店铺吗?", "确认清空?", function() {
        $.post('/antique/api/userShopCollection/clear_collection_log', {
            token: getCookie('token')
        }, function (result) {
            $.toast("清空关注店铺成功!",function(){
                window.location.reload();
            },1000);
        });
    }, function() {
        //取消操作
    });
});